css: Add a check function for specified types
authorBenjamin Otte <otte@redhat.com>
Sun, 15 Jan 2012 01:30:26 +0000 (02:30 +0100)
committerBenjamin Otte <otte@redhat.com>
Thu, 2 Feb 2012 02:14:00 +0000 (03:14 +0100)
... and use it.

It seems kinda necessary for the refactoring I'm about to do...

gtk/gtkcssprovider.c
gtk/gtkcssstyleproperty.c
gtk/gtkcssstylepropertyprivate.h

index 7d2f18329d9941b1ae3f9a1e1d658024ee098d1d..927d345b68145bbed53346f31db32ab6e5ac9c71 100644 (file)
@@ -1212,6 +1212,9 @@ gtk_css_ruleset_add (GtkCssRuleset    *ruleset,
     }
   else if (GTK_IS_CSS_STYLE_PROPERTY (prop))
     {
+      g_return_if_fail (_gtk_css_style_property_is_specified_type (GTK_CSS_STYLE_PROPERTY (prop),
+                                                                   G_VALUE_TYPE (&value->value)));
+
       _gtk_bitmask_set (ruleset->set_styles,
                         _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (prop)),
                         TRUE);
index 348ea0d163edcfa49052d9267046ce62a054a09f..ad713ec422504ffdbe1adf0350924a078248bc8e 100644 (file)
@@ -28,6 +28,7 @@
 #include "gtkprivatetypebuiltins.h"
 #include "gtkstylepropertiesprivate.h"
 
+#include <cairo-gobject.h>
 #include "gtkcssimagegradientprivate.h"
 #include "gtkcssimageprivate.h"
 
@@ -441,6 +442,28 @@ _gtk_css_style_property_get_specified_type (GtkCssStyleProperty *property)
   return G_VALUE_TYPE (&property->initial_value);
 }
 
+gboolean
+_gtk_css_style_property_is_specified_type (GtkCssStyleProperty *property,
+                                           GType                type)
+{
+  g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), FALSE);
+
+  /* If it's our specified type, of course it's valid */
+  if (type == G_VALUE_TYPE (&property->initial_value))
+    return TRUE;
+
+  /* The special values 'inherit' and 'initial' are always valid */
+  if (type == GTK_TYPE_CSS_SPECIAL_VALUE)
+    return TRUE;
+
+  /* XXX: Someone needs to fix that legacy */
+  if (G_VALUE_TYPE (&property->initial_value) == CAIRO_GOBJECT_TYPE_PATTERN &&
+      type == GTK_TYPE_GRADIENT)
+    return TRUE;
+
+  return FALSE;
+}
+
 /**
  * _gtk_css_style_property_compute_value:
  * @property: the property
index 84cb1d2d8c8022f9b3f0dfd0eebcb6e681b86b49..d207595b3484785c306015fe19d84506855cb50d 100644 (file)
@@ -80,6 +80,8 @@ const GValue *          _gtk_css_style_property_get_initial_value
                                                                 (GtkCssStyleProperty    *property);
 GType                   _gtk_css_style_property_get_computed_type (GtkCssStyleProperty *property);
 GType                   _gtk_css_style_property_get_specified_type (GtkCssStyleProperty *property);
+gboolean                _gtk_css_style_property_is_specified_type (GtkCssStyleProperty  *property,
+                                                                 GType                   type);
 
 void                    _gtk_css_style_property_compute_value   (GtkCssStyleProperty    *property,
                                                                  GValue                 *computed,